モジュール:Sandbox/TimeTest
local p = {} itis = "Fight it out." D = {} J = {} T = {} function BirthdayInsert(Date, Japanese, Transliterated) table.insert(D, Date) table.insert(J, Japanese) table.insert(T, Transliterated) end BirthdayInsert('1984-07-17', '木村麻美', 'Kimura Asami') BirthdayInsert('2000-07-21', '田口夏実', 'Taguchi Natsumi') BirthdayInsert('1980-07-22', '北上アミ', 'Kitagami Ami') BirthdayInsert('1998-07-28', '岡村里星', 'Okamura Rise') BirthdayInsert('1989-07-23', '鍾安琪', 'Zhong An Qi') BirthdayInsert('1994-08-01', '和田彩花', 'Wada Ayaka') BirthdayInsert('1998-08-05', '鈴木香音', 'Suzuki Kanon') BirthdayInsert('1981-08-08', '飯田圭織', 'Iida Kaori') BirthdayInsert('1981-08-10', '安倍なつみ', 'Abe Natsumi') BirthdayInsert('1979-08-14', '三佳千夏', 'Miyoshi Chinatsu') BirthdayInsert('1992-08-25', '夏焼雅', 'Natsuyaki Miyabi') BirthdayInsert('1986-08-26', '川島幸', 'Kawashima Miyuki') BirthdayInsert('2001-08-26', '斎藤夏奈', 'Saito Kana') BirthdayInsert('1979-08-28', '前田有紀', 'Maeda Yuki') BirthdayInsert('1992-08-28', '趙國蓉', 'Zhao Guo Rong') BirthdayInsert('1998-08-28', '三瓶海南', 'Mikame Kana') BirthdayInsert('1999-08-29', '真城佳奈', 'Mashiro Kana') BirthdayInsert('2000-08-31', '井上ひかる', 'Inoue Hikaru') BirthdayInsert('1990-09-05', '阿部麻美', 'Abe Asami') BirthdayInsert('1983-09-06', 'ダニエル・デラウニー', 'Danielle Delaunay') BirthdayInsert('1996-09-06', '木沢留那', 'Kizawa Runa') function p.test() return "Hello, world!" end function p.test2() return "2014-02-28 " .. (os.time{year=2014, month=02, day=28}) .. " 2014-02-29 " .. (os.time{year=2014, month=02, day=29}) .. " 2014-03-01 " .. (os.time{year=2014, month=03, day=01}) end function ostime (y,m,d) return os.time{year=y, month=m, day=d} end function ostimehyphen (yyyymmdd) _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return ostime(y,m,d) end function ostimehyphen2000 (yyyymmdd) _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return ostime(2000,m,d) end function ostimeNOWJST2000 () return ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400)) end function ostimeNEXJST2000(days) local num_days = days or 7 return ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400+(num_days-1)*86400)) end function hyphentodayofyear(yyyymmdd) return os.date("%j", ostimehyphen(yyyymmdd)) end function p.test3() return "2014-02-28 " .. ostime(2014, 02, 28) .. " 2014-02-29 " .. ostime(2014, 02, 29) .. " 2014-03-01 " .. ostime(2014, 03, 01) end function TheScope () itis = "THIS BIG" end function p.test4() Thing = "The scope is " .. itis TheScope() Thing = Thing .. " The scope is " .. itis return Thing end function p.test5() return T1 .. " " .. T2 end function p.test6() return os.date("%c") end function p.test7() return "2014-02-28-0 " .. (os.time{year=2014, month=02, day=28, hour=0}) .. " 2014-02-28-9 " .. (os.time{year=2014, month=02, day=28, hour=9}) end function p.test8() return "NOW: " .. os.time() .. " JST: " .. os.time()+32400 end function p.test9() return "NOW: " .. os.date("%c") .. " JST: " .. os.date("%c", os.time()+32400) end function p.test10() return ":Easy\n:listening?" end function p.test11() return " NOWJST2000: " .. os.date("%Y-%m-%d",os.time()+32400) end function p.test11a() return " NOWJST2000a: " .. ostimehyphen(os.date("%Y-%m-%d",os.time()+32400)) end function p.test11b() return " NOWJST2000b: " .. ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400)) end function p.test12() return " Zukki: " .. ostimehyphen(D2) .. " " .. ostimehyphen2000(D2) end function p.test13() return ostimehyphen('2014-08-05') end function p.test13a() return ostimehyphen2000('2014-08-05') end function p.test14() yyyymmdd = "1990-07-17" _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return "Y " .. y .. " M " .. m .. " D " .. d end function p.testx2() date = "17/7/1990" _, _, d, m, y = string.find(date, "(%d+)/(%d+)/(%d+)") return y .. " " .. m .. " " .. d end function p.test15() return "ostimeNOWJST2000: " .. ostimeNOWJST2000() end function p.test16() return "ostimeNEXJST2000: " .. ostimeNEXJST2000() end function p.upcoming(frame) --local num_days = frame.args.days or 7 --local num_min = frame.args.min or 2 local num_days = tonumber(frame.args.days or 7) local num_min = tonumber(frame.args.min or 2) NOWJST2000 = ostimeNOWJST2000() NEXJST2000 = ostimeNEXJST2000(num_days) output = "" counter = 0 first = 0 lastdate = 0 for i=1, table.getn(D), 1 do output = output .. ":[.. T[i .. "]] (" .. Di .. ")" if ostimehyphen2000(Di) >= NOWJST2000 and ostimehyphen2000(Di) <= NEXJST2000 then output = output .. " It's both." if ostimehyphen2000(Di) ~= lastdate then if ostimehyphen2000(Di) NOWJST2000 then output = output .. " HAPPY BIRTHDAY" else output = output .. " COMING SOON" end end lastdate = ostimehyphen2000(Di) counter = counter+1 if first 0 then first = i if ostimehyphen2000(Di+num_min-1) > NEXJST2000 then NEXJST2000 = ostimehyphen2000(Di+num_min-1) end --Minimum goes to this date, so make that date the finish date. end end output = output .. "\n" end output = output .. "There were " .. counter .. ". " output = output .. "I wanted " .. num_min .. ". " if counter >= num_min then output = output .. "That's enough." else output = output .. "That's not enough." end return output .. " " .. os.clock() end function p.test17() return "NOW: " .. os.date("%c") .. " Different: " .. os.date("%j") end function p.test18() return "01-01: " .. hyphentodayofyear('2000-01-01') .. " 02-01: " .. hyphentodayofyear('2000-02-01') .. " 03-01: " .. hyphentodayofyear('2000-03-01') .. " 03-01: " .. hyphentodayofyear('2014-03-01') .. " 02-29: " .. hyphentodayofyear('2014-02-29') end function p.test19() return os.clock() end return p